import {
  menuAddRequest,
  menuDeleteRequest,
  menuUpdateRequest,
  getMenuOptionsRequest,
  getMenuListRequest,
} from "@/api/system/menu";
export const useMenuStore = defineStore("menu", {
  state: () => ({
    menuOptions: [],
    menuList: [],
  }),
  actions: {
    async getMenuOptions() {
      const res = (await getMenuOptionsRequest()) as any;
      this.menuOptions = res.data;
    },
    async menuAdd(params: any) {
      const res = (await menuAddRequest(params)) as any;
      if (res.code == 200) {
        ElMessage.success("添加成功");
        params.callback && params.callback();
      }
      return res;
    },
    async menuUpdate(params: any) {
      const res = await menuUpdateRequest(params);
      if (res.code == 200) {
        ElMessage.success("修改成功");
        params.callback && params.callback();
      }
      return res;
    },
    async menuDelete(params: any) {
      const res = (await menuDeleteRequest(params)) as any;
      if (res.code == 200) {
        ElMessage.success("删除成功");
        params.callback && params.callback();
      }
    },
    async getMenuListRequest() {
      const res = (await getMenuListRequest()) as any;
      this.menuList = res.data || [];
    },
  },
});
